import turtle
import datetime
import time

# 长度
forward_len = 40
# 转角角度
steer_angle = 90
# 空间隔长度
blank_len = 20
hour_xy_1 = [-160, 40]
hour_xy_2 = [-100, 40]
minute_xy_1 = [-30, 40]
minute_xy_2 = [30, 40]
second_xy_1 = [100, 40]
second_xy_2 = [160, 40]


def bihua_num(num, time_type, time_num):
    turtle.penup()
    turtle.setheading(0)
    turtle.speed(0)
    if time_type == 'hour':
        if time_num == 0:
            turtle.goto(hour_xy_1[0], hour_xy_1[1])
        else:
            turtle.goto(hour_xy_2[0], hour_xy_2[1])
    elif time_type == 'minute':
        if time_num == 0:
            turtle.goto(minute_xy_1[0], minute_xy_1[1])
        else:
            turtle.goto(minute_xy_2[0], minute_xy_2[1])
    elif time_type == 'second':
        if time_num == 0:
            turtle.goto(second_xy_1[0], second_xy_1[1])
        else:
            turtle.goto(second_xy_2[0], second_xy_2[1])
    turtle.pendown()
    if num == 0:
        turtle.forward(forward_len)
        turtle.right(steer_angle)
        turtle.forward(forward_len * 2)
        turtle.right(steer_angle)
        turtle.forward(forward_len)
        turtle.right(steer_angle)
        turtle.forward(forward_len * 2)
    elif num == 1:
        turtle.penup()
        turtle.forward(forward_len)
        turtle.pendown()
        turtle.right(steer_angle)
        turtle.forward(forward_len * 2)
    elif num == 2:
        turtle.forward(forward_len)
        turtle.right(steer_angle)
        turtle.forward(forward_len)
        turtle.right(steer_angle)
        turtle.forward(forward_len)
        turtle.left(steer_angle)
        turtle.forward(forward_len)
        turtle.left(steer_angle)
        turtle.forward(forward_len)
    elif num == 3:
        turtle.forward(forward_len)
        turtle.right(steer_angle)
        turtle.forward(forward_len)
        turtle.right(steer_angle)
        turtle.forward(forward_len)
        turtle.left(steer_angle * 2)
        turtle.forward(forward_len)
        turtle.right(steer_angle)
        turtle.forward(forward_len)
        turtle.right(steer_angle)
        turtle.forward(forward_len)
    elif num == 4:
        turtle.right(steer_angle)
        turtle.forward(forward_len)
        turtle.left(steer_angle)
        turtle.forward(forward_len)
        turtle.penup()
        turtle.left(steer_angle)
        turtle.forward(forward_len)
        turtle.left(steer_angle * 2)
        turtle.pendown()
        turtle.forward(forward_len * 2)
    elif num == 5:
        turtle.penup()
        turtle.forward(forward_len)
        turtle.right(steer_angle * 2)
        turtle.pendown()
        turtle.forward(forward_len)
        turtle.left(steer_angle)
        turtle.forward(forward_len)
        turtle.left(steer_angle)
        turtle.forward(forward_len)
        turtle.right(steer_angle)
        turtle.forward(forward_len)
        turtle.right(steer_angle)
        turtle.forward(forward_len)
    elif num == 6:
        turtle.penup()
        turtle.forward(forward_len)
        turtle.right(steer_angle * 2)
        turtle.pendown()
        turtle.forward(forward_len)
        turtle.left(steer_angle)
        turtle.forward(forward_len * 2)
        turtle.left(steer_angle)
        turtle.forward(forward_len)
        turtle.left(steer_angle)
        turtle.forward(forward_len)
        turtle.left(steer_angle)
        turtle.forward(forward_len)
    elif num == 7:
        turtle.forward(forward_len)
        turtle.right(steer_angle)
        turtle.forward(forward_len * 2)
    elif num == 8:
        turtle.forward(forward_len)
        turtle.right(steer_angle)
        turtle.forward(forward_len)
        turtle.right(steer_angle)
        turtle.forward(forward_len)
        turtle.left(steer_angle)
        turtle.forward(forward_len)
        turtle.left(steer_angle)
        turtle.forward(forward_len)
        turtle.left(steer_angle)
        turtle.forward(forward_len)
        turtle.left(steer_angle)
        turtle.forward(forward_len)
        turtle.right(steer_angle)
        turtle.forward(forward_len)
    elif num == 9:
        turtle.penup()
        turtle.forward(forward_len)
        turtle.right(steer_angle * 2)
        turtle.pendown()
        turtle.forward(forward_len)
        turtle.left(steer_angle)
        turtle.forward(forward_len)
        turtle.left(steer_angle)
        turtle.forward(forward_len)
        turtle.penup()
        turtle.left(steer_angle)
        turtle.forward(forward_len)
        turtle.pendown()
        turtle.right(steer_angle * 2)
        turtle.forward(forward_len * 2)
        turtle.right(steer_angle)
        turtle.forward(forward_len)


def clock_demo():
    while True:
        # 获取当前时间
        now = datetime.datetime.now()
        # 分别获取时、分、秒
        hour_1, hour_2 = divmod(now.hour, 10)
        minute_1, minute_2 = divmod(now.minute, 10)
        second_1, second_2 = divmod(now.second, 10)
        bihua_num(hour_1, 'hour', 0)
        bihua_num(hour_2, 'hour', 1)
        bihua_num(minute_1, 'minute', 0)
        bihua_num(minute_2, 'minute', 1)
        bihua_num(second_1, 'second', 0)
        bihua_num(second_2, 'second', 1)
        time.sleep(1)
        turtle.reset()


clock_demo()

# now = datetime.datetime.now()
# hour_1, hour_2 = divmod(now.hour, 10)
# minute_1, minute_2 = divmod(now.minute, 10)
# second_1, second_2 = divmod(now.second, 10)
# print(hour_1, hour_2, minute_1, minute_2, second_1, second_2)
# now = datetime.datetime.now().strftime('%H%M%S')
# for i, num in enumerate(now):
#     print(i,num)